package com.example.design.ddd.practice.adapter.driving.restful.orgmng;

import com.example.design.ddd.practice.application.orgmng.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class OrgController {
    @Autowired
    OrgService orgService;

    @PostMapping("/api/organizations")
    public OrgResponse addOrg(@RequestBody CreateOrgRequest request) throws Throwable {
        //从请求里解析出 userId ...
        Long userId = 123L;
        return orgService.addOrg(request, userId);
    }

    @PatchMapping("/api/organizations/{id}")
    public OrgResponse updateOrgBasic(@PathVariable Long id
            , @RequestParam("userid") Long userId
            , @RequestBody UpdateOrgBasicRequest request) {
        //Long user = acquireUserId();
        return orgService.updateOrgBasic(id, request, userId);
    }


    @PostMapping("/api/organizations/{id}/cancel")
    public Long cancelOrg(@PathVariable Long id
            , @RequestParam("userid") Long userId
            , @RequestParam Long tenant) {
        //Long user = acquireUserId();
        return orgService.cancelOrg(tenant, id, userId);
    }
}